package servlet;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import entity.Movie;
import service.MovieService;

/**
 * Servlet implementation class UpdateMovie
 */
@WebServlet("/UpdateMovie")
public class UpdateMovie extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public UpdateMovie() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");

		Movie movie = new Movie();
		movie.setName(request.getParameter("name"));
		movie.setType(request.getParameter("type"));
		movie.setActor(request.getParameter("actor"));
		movie.setDirector(request.getParameter("director"));
		movie.setLength(Integer.parseInt(request.getParameter("length")));
		movie.setMark(Float.parseFloat(request.getParameter("mark")));
		movie.setPrice(Float.parseFloat(request.getParameter("price")));
		movie.setIntroduce(request.getParameter("introduce"));
		
		String mid = request.getParameter("mid");
		MovieService ms =new MovieService();
		ms.update(movie, mid);
		
		response.sendRedirect("update_movie.jsp");
		
		/*PrintWriter out = response.getWriter();
		//out.println("<%@ page language="java" import='java.util.*' pageEncoding='utf-8' %> ");
		
		out.println(request.getParameter("mid"));*/
		
		
	}

}
